﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QLVMB
{
    public partial class frmThemChuyenBay : Form
    {
        public frmThemChuyenBay()
        {
            InitializeComponent();
        }

        public void ThemChuyenBay(DTO.ChuyenBay chuyenbay, DTO.ChiTietChuyenBay chitietchuyenbay)
        {
            chuyenbay.MaChuyenBay = txtMaChuyenBay.Text;
            chuyenbay.NgayBay = DateTime.Parse(dateTimePicker1.Value.ToString());
            DateTime a = new DateTime(2011, 1, 1, int.Parse(cbGio.Text), int.Parse(cbPhut.Text), 0);
            chuyenbay.ThoiGian = a;
            chuyenbay.MaSanBayDi = int.Parse(txtSanBayDi.Text);
            chuyenbay.MaSanBayDen = int.Parse(txtSanBayDen.Text);
            chuyenbay.SoGheThuongGia = int.Parse(txtSoGheHang1.Text);
            chuyenbay.SoGhePhoThong = int.Parse(txtSoGheHang2.Text);
            chuyenbay.MaLoaiMayBay = int.Parse(txtMaLoaiMayBay.Text);
            chitietchuyenbay.SanBayTrungGian = int.Parse(txtSBTrungGian.Text);
            chitietchuyenbay.ThoiGianDung = DateTime.Parse(cbGioDung.Text+":"+cbPhutDung.Text);
        }

        private void btThem_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMaChuyenBay.Text == "" || txtMaLoaiMayBay.Text == "" || txtSanBayDi.Text == "" || txtSanBayDen.Text == "" || txtSoGheHang1.Text == "" || txtSoGheHang2.Text == "")
                {
                    MessageBox.Show("Nhap lai du lieu");
                    return;
                }
                DTO.ChuyenBay chuyenbay = new DTO.ChuyenBay();
                DTO.ChiTietChuyenBay chitietchuyenbay = new DTO.ChiTietChuyenBay();
                ThemChuyenBay(chuyenbay, chitietchuyenbay);
                chitietchuyenbay.MaChuyenBay = chuyenbay.MaChuyenBay;
                if (BUS.ChuyenBayBUS.ThemChuyenBay(chuyenbay) == BUS.ChuyenBayBUSResult.OK && BUS.ChiTietChuyenBayBUS.ThemChuyenBay(chitietchuyenbay) == BUS.ChiTietChuyenBayBUSResult.OK)
                {
                    MessageBox.Show("Them thanh cong");
                }
            }
            catch 
            {
                MessageBox.Show("Lỗi");
            }
            

            
        }

       

        private void frmThemChuyenBay_Load(object sender, EventArgs e)
        {
            for (int i = 0; i <= 23; i++)
            {
                cbGio.Items.Add(i);
            }
            for (int i = 0; i <= 60; i++)
            {
                cbPhut.Items.Add(i);
            }
            cbGio.SelectedIndex = 0;
            cbPhut.SelectedIndex = 0;
        }

        private void btQuayLai_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }

}